<template>
  <el-container class="license-warp">
    <TopFilter ref="formPanel" :list="formList" :cols="3" @filterChange="getClssList" />
    <FilterTable
      ref="table"
      :columns="columns"
      columnsRef="partInventoryManagerPatrItemAdjustLicenseSelect"
      :fetchapi="fetchApi"
      :params="fetchParams"
      selectionType="single"
      :datakey="'rows'"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="arr => (this.onChangeColumn = arr)"
    ></FilterTable>
    <div class="bottomBtn">
      <el-button type="primary" :loading="addBtnState" @click="saveDialog">确 定</el-button>
      <el-button @click="closeDialog">取 消</el-button>
    </div>
  </el-container>
</template>
<script>
import { getClssList } from '@/api/repair/repairReception/customer';

export default {
  props: ['licenseNo'],
  data() {
    return {
      formList: this.createFormList(),
      addBtnState: null,
      fetchApi: getClssList,
      fetchParams: { xhrAbort: true },
      columns: this.createTableColumns(),
      onChangeColumn: []
    };
  },
  watch: {
    licenseNo: {
      handler(str) {
        console.log(str);
        this.formList.some(item => {
          console.log(item);

          if (item.fieldName === 'license') {
            item.initialValue = str;
            return true;
          }
        });
      },
      immediate: true
    }
  },
  mounted() {
    // this.query();
  },
  methods: {
    createFormList() {
      return [
        {
          type: 'INPUT',
          label: '车牌号',
          fieldName: 'license',
          placeholder: ''
        },
        {
          type: 'INPUT',
          label: 'VIN',
          fieldName: 'vin',
          placeholder: ''
        },
        {
          type: 'INPUT',
          label: '车主',
          fieldName: 'ownerName',
          placeholder: ''
        }
      ];
    },
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '车牌号',
          dataIndex: 'LICENSE',
          showOverflowTooltip: true,
          sorter: true
        },
        {
          title: 'VIN',
          dataIndex: 'VIN',align: 'center',
          width: 180,
          showOverflowTooltip: true,
          sorter: true
        },
        {
          title: '发动机号',
          dataIndex: 'ENGINE_NO',
          sorter: true
        },
        {
          title: '车主',
          dataIndex: 'OWNER_NAME',
          sorter: true
        },
        {
          title: '品牌',
          dataIndex: 'BRAND_NAME',
          sorter: true
        },
        {
          title: '车系',
          dataIndex: 'SERIES_NAME',
          showOverflowTooltip: true,
          sorter: true
        },
        {
          title: '车型',
          dataIndex: 'MODEL_NAME',
          showOverflowTooltip: true,
          sorter: true
        }
      ];
    },
    formChangeHandle() {},
    closeDialog() {
      this.$emit('closeDialog', false);
    },
    saveDialog() {
      if (!this.onChangeColumn || !this.onChangeColumn.length) {
        return this.$notify.warning({ title: '提示信息', message: '请选中一条数据' });
      }
      this.$emit('onConfirm', this.onChangeColumn[0].LICENSE);
      this.closeDialog();
    },
    getClssList(val) {
      this.fetchParams.xhrAbort = true;
      this.fetchParams = Object.assign(this.fetchParams, val, { xhrAbort: false });
    }
  }
};
</script>
<style lang="less" scoped>
.bottomBtn {
  position: absolute;
  left: 0px;
  bottom: 0px;
  right: 0px;
  z-index: 9;
  border-top: 1px solid rgb(233, 233, 233);
  padding: 10px 20px;
  background: rgb(255, 255, 255);
  text-align: right;
}
.license-warp {
  flex-direction: column;

  /* .top {
    width: 100%;
    display: flex;
    flex-direction: column;

    .el-row {
      text-align: center;
    }
  }

  .footer {
    text-align: center;
  } */
}
</style>
